import os


def fileRename(dir):
    listdir = os.listdir(dir)
    for datedir in listdir:
        # 判断文件还是文件夹
        childdir = dir + '\\' + datedir
        if os.path.isfile(childdir):
            if datedir.endswith('.ok'):
                print(str(childdir) + '删除文件')
                os.remove(childdir)
                continue
            elif datedir.endswith('.csv.csv'):
                print(str(childdir) + '重命名文件')
                os.rename(childdir, childdir.split(".")[0] + '.csv')
                continue
            elif datedir.endswith('.csv'):
                print(str(childdir) + '跳过文件')
                continue
            else:
                print(str(childdir) + '重命名文件')
                os.rename(childdir, childdir + '.csv')
                continue
        if os.path.isdir(childdir):
            fileRename(childdir)


if __name__ == '__main__':
    fileRename('D:\\data\\accountfile\\car_prod')
